package trial;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @创建人 MBY381
 * @创建时间 2022/4/29 19:14
 * @描述 暂无
 */
public class JDco {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(3);
        list.add(4);
        list.add(5);
        list.add(2);
        System.out.println(list);
        Collections.sort(list);
        System.out.println(list);
        list.add(3, 10);
        System.out.println(list);
        System.out.println(jc(2, 2));
        test();
        System.out.println();
    }

    public static void test2() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        long ans = 0;
        int topIndex = 2;
        long ding = n - k + 1, di = 1, bottomIndex = ding - k;
        for (int i = k; i < n; i = i + k) {
//            System.out.println(di + " / " + ding);
            ans += ding / di;
            di *= topIndex;
//            System.out.println();
//            System.out.println("b"+bottomIndex+"  "+"t "+topIndex);
            ding = jc(bottomIndex, topIndex);
            topIndex++;
            bottomIndex = bottomIndex - k;
        }
        if (n < 0 || k < 0) {
            ans = 0;
        } else if (n < 2 || k < 2) {
            ans = 1;
        } else {
            if (n % k == 0) {
                ans = ans + 2;
            } else {
                ans++;
            }

        }
        System.out.println(ans % 998244353);
    }

    public static long jc(long i, long k) {
        long ans = 1;
        for (int j = 0; j < k; j++) {
            ans *= i--;
        }
        return ans;
    }

    public static void test() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        if (n == 0) {
            return;
        }
        if (n == 1) {
            System.out.println(sc.nextInt());
            return;
        }
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        Collections.sort(list);
        while (list.size() > 1) {
            int len = list.size();
            int value = (list.get(0) + list.get(len - 1)) / 2;
            if (list.size() == 2) {
                list.clear();
                list.add(value);
                break;
            }
            list.remove(len - 1);
            list.remove(0);
            int index = list.size() / 2;
            int val = list.get(index);
            if (val > value) {
                while (index > 0 && list.get(index) > value) {
                    index--;
                }
            } else if (val < value) {
                while (index < list.size() && list.get(index) < value) {
                    index++;
                }
            }
//            System.out.println(list+"before");
            list.add(index, value);
//            System.out.println(list);
        }
        System.out.println(list.get(0));
    }

}
